package com.bee.tlweb.util;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.beetl.core.GroupTemplate;
import org.beetl.ext.jsp.IncludeJSPTag;
import org.beetl.ext.servlet.ServletGroupTemplate;
import org.beetl.ext.tag.cache.CacheTag;



/**
 * Application Lifecycle Listener implementation class BeetlInitListener
 *
 */
public class BeetlInitListener implements ServletContextListener {

    /**
     * Default constructor. 
     */
    public BeetlInitListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent arg0) {
    	try{
    		GroupTemplate gt = ServletGroupTemplate.instance().getGroupTemplate();
   		
        
    		gt.registerFormat("samples.xss", new XSSDefenseFormat());    	
    		gt.registerFunction("samples.join", new JoinFunction());
    		gt.registerTag("cache", CacheTag.class);
    		gt.registerTag("includeJSP", IncludeJSPTag.class);
    		
    	
    	}catch(Exception ex){
    		ex.printStackTrace();
    	}
    	
    	
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0) {
    	//ServletGroupTemplate.intance().getGroup().close();
    }
	
}
